<template>
  <div class="side">
    <div class="register">
      <el-row>
        <el-button type="primary" @click="createData" class="dakai">提交</el-button>
      </el-row>
    </div>
    <!-- 课程 -->
    <div style="width:100%">
      <el-form :model="CourseSet" label-position="right" label-width="180px" ref="dataForm">
        <el-form-item label="给新学员发送欢迎私信 ">
          <el-radio-group v-model="CourseSet.isSetMessage">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">开启后，新学员加入课程后，会收到教师的欢迎私信 </p>
        </el-form-item>

        <el-form-item label="欢迎私信内容">
          <el-input :rows="4" v-model="CourseSet.messageContent" style="width:450px" type="textarea"/>
          <p style="margin:0;color:#606266">变量说明：{{nickname}} 为接收方用户用户名{{course}} 为课程名称</p>
        </el-form-item>
        <el-form-item label="课程详情页显示相关课程 ">
          <el-radio-group v-model="CourseSet.isShowCourse">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">根据课程的标签，显示相关课程</p>
        </el-form-item>

        <!-- 权限于版权 -->
        <div class="quanxian">权限于版权</div>
        <el-form-item label="允许教师管理基础设置 ">
          <el-radio-group v-model="CourseSet.isManageBaseSet">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="允许教师查询课程订单 ">
          <el-radio-group v-model="CourseSet.isQueryCourseOrders">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="允许教师添加/移除学员 ">
          <el-radio-group v-model="CourseSet.allowAddAndRemoveUser">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="允许教师导出学员资料 ">
          <el-radio-group v-model="CourseSet.allowExportStuData">
            <el-radio label="1">是</el-radio>
            <el-radio label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="课程列表默认排序 ">
          <el-radio-group v-model="CourseSet.courseListDefaultSort">
            <el-radio label="1">最新</el-radio>
            <el-radio label="2">最热</el-radio>
            <el-radio label="3">推荐</el-radio>
          </el-radio-group>
          <div style="width:623px;height:25px;line-height:22px;">
            <a style="color:#428bcb">课程列表页</a><span style="color:#727272">地址：域名/course/explore,任何人都可在此页面查看网站所有已发布课程,如需设置网站首页课程排序，请到【站点设置】-【主题】-【管理】中设置，目前仅简墨和雅致简洁主题支持.</span>
          </div>
        </el-form-item>
        <el-form-item label="文档任务防复制 ">
          <el-radio-group v-model="CourseSet.docTaskCopy">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="试卷防复制 ">
          <el-radio-group v-model="CourseSet.testPaperCopy">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- 课程运营模式 -->
        <div class="kechengxunying">课程运营模式</div>
        <el-form-item label="免费试看/免费任务允许未登录用户观看 ">
          <el-radio-group v-model="CourseSet.freeTaskForNoLogin">
            <el-radio label="1">允许</el-radio>
            <el-radio label="0">不允许</el-radio>
          </el-radio-group>
          <p style="margin:0;color:#606266">如果允许此项设置，未登录用户（游客）可观看免费试看/免费任务</p>
        </el-form-item>
        <el-form-item label="课程中允许显示课程人数 ">
          <el-radio-group v-model="CourseSet.isShowCourseNum">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>

        <!-- 章节名称自定义 -->
        <div class="zhangjie">章节名称自定义</div>
        <div style="margin-top:10px;">
          <el-form-item label="设置章名称">
            <el-input style="width:300px;" v-model="CourseSet.chapter" placeholder="章"></el-input>
          </el-form-item>
        </div>
        <el-form-item label="设置节名称">
          <el-input style="width:300px;" v-model="CourseSet.draft" placeholder="节"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import {addCourseSet, getCourseSet} from '@/api/system/course_set';
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        nickname: '',
        course: '',
        CourseSet: {
          isSetMessage: '',
          messageContent: '',
          isShowCourse: '',
          isManageBaseSet: '',
          isQueryCourseOrders: '',
          allowAddAndRemoveUser: '',
          allowExportStuData: '',
          courseListDefaultSort: '',
          docTaskCopy: '',
          testPaperCopy: '',
          freeTaskForNoLogin: '',
          isShowCourseNum: '',
          chapter: '',
          draft: '',
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getCourseSet(getTenantId()).then(response => {
          this.CourseSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.CourseSet.tenantId = getTenantId();
            addCourseSet(this.CourseSet).then(() => {
              this.$notify({
                title: '成功',
                message: '创建成功',
                type: 'success',
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .register {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
    margin-left: 0px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }

  .money {
    width: 100%;
    height: 44px;
    line-height: 44px;
    margin-left: 15px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-right: 34px;
  }

  .quanxian {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #f0f3ff;
    padding-right: 34px;
    margin-left: 0px;
  }

  .kechengxunying {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #ebf4ff;
    padding-right: 34px;
    margin-left: 0px;
  }

  .zhangjie {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e4fafd;
    padding-right: 34px;
    margin-left: 0px;
  }
</style>
